﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DecisionTree
{
    struct FeatureProperty
    {
        public byte average;
        public byte min;
        public byte max;
        public byte standardDeviation;

        public override string ToString()
        {
            return "min: " + min.ToString("D3") + " max: " + max.ToString("D3") + " av: " + average.ToString("D3") + " std " + standardDeviation.ToString("D3");
        }
    }

    static class FeaturePropertyWorker
    {
        public static FeatureProperty[] GetProperties(byte[][] inputs)
        {
            FeatureProperty[] rVal = new FeatureProperty[inputs[0].Length];

            for (int i = 0; i < rVal.Length; i++)
            {
                byte[] featureItems = new byte[inputs.Length];

                for (int j = 0; j < inputs.Length; j++)
                {
                    featureItems[j] = inputs[j][i];
                }

                byte min = featureItems.Min();
                byte max = featureItems.Max();
                byte average = featureItems.Average();
                byte stdDev = featureItems.StandardDeviation();

                rVal[i] = new FeatureProperty() { min = min, max = max, average = average, standardDeviation = stdDev };
            }

            return rVal;
        }

        public static void Dowork()
        {
            byte[][] inputs = FileOperations.ReadImages(Parameters.TrainInputPath);
            FeatureProperty[] result = GetProperties(inputs);

            using (TextWriter writer = File.CreateText("C:\\properties.txt"))
            {
                for (int i = 0; i < result.Length; i++)
                {
                    writer.WriteLine("#"+i.ToString("D3") + " " + result[i]);
                }
            }
        }
    }

}
